import csv

import yaml
import json
from openpyxl import load_workbook
from pathlib import Path

def read_yaml(file):
    with open(Path(__file__).parent.parent/"data"/file,'r',encoding='utf-8') as f:
        return yaml.safe_load(f)

def read_json(file):
    with open(Path(__file__).parent.parent/"data"/file,'r',encoding='utf-8')as f:
        data = json.load(f)
        return data


def read_excel(file_path):
    wb = load_workbook(r"C:\Users\34098\PycharmProjects\Auto_wms\API_wms\data\canshu.xlsx")
    sheet = wb["Sheet1"]
    test_data = []
    for row in sheet.iter_rows(min_row=2, values_only=True):
        # 将每行数据与表头组合成字典
        data = row
        test_data.append(data)
    wb.close()
    return test_data

def read_csv(file_path):
    test_data = []
    with open(file_path, mode='r', encoding='gbk') as f:
        reader = csv.DictReader(f)
        for row in reader:
            test_data.append(row)
        return test_data